#ifndef GETPIDPACKAGE_H
#define GETPIDPACKAGE_H
#include <stdio.h>
#include <stdlib.h>

#define PACKAGE_MAX_LENGTH 204

typedef struct
{
    unsigned int sync_byte :8; //define 0x47
    unsigned int transport_error_indicator :1;
    unsigned int payload_unit_start_indicator :1;
    unsigned int transport_priority :1;
    unsigned int PID :13;
    unsigned int transport_scrambling_control :2;
    unsigned int adaption_field_control :2;
    unsigned int continuity_counter :4;
} TS_PACKAGE_HEAD;


class GetPidPackage
{
public:
    ~GetPidPackage();
    GetPidPackage(const GetPidPackage&)=delete;
    GetPidPackage& operator=(const GetPidPackage&)=delete;
    static GetPidPackage& get_instance();

    /*********************************************************************************************************************************
     * Function Name : ParseTS_PackageHead
     * Description   : parse the TS package head
     * Parameters    :
     *				pstTS_PackageHead -- the package head structure
     *				pucBufferPackage -- the package buffer
     * Returns       : void
     *********************************************************************************************************************************/
    void ParseTS_PackageHead(TS_PACKAGE_HEAD *pstTS_PackageHead, unsigned char *pucPackageBuffer);
    /*********************************************************************************************************************************
     * Function Name : SavePID_Packege
     * Description   : get all the PID package which we want and save they in the file
     * Parameters    :
     *				pfTsFile -- the TS file descriptor
     *				iTsPosition -- the TS package begin position
     *				iTsLength -- the TS package length
     *				puiWantPID -- the package PID which we want
     *				pfSaveFile -- the save file descriptor
     * Returns       : -1 - get package failure 0 - get package save success
     *********************************************************************************************************************************/
    int SavePID_Packege(FILE *pfTsFile, int iTsPosition, int iTsLength, unsigned int *puiWantPID, FILE *pfSaveFile);
private:
    /*********************************************************************************************************************************
     * Function Name : IsWantPid
     * Description   : is we want PID (the first position of the array save the PID count )
     * Parameters    :
     *				puiWantPID -- save the want PID
     *				uiPID -- PID
     * Returns       : 0 - not the want PID 1 - yes the want PID
     *********************************************************************************************************************************/
    int IsWantPid(unsigned int *puiWantPID, unsigned int uiPID);
private:
    GetPidPackage();
};

#endif // GETPIDPACKAGE_H
